home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11746 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.6 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.os.msdos.programmer,comp.dsp,comp.lang.c
  4. Subject: Re: using C to access the Soundblaster
  5. Date: 25 Mar 1996 11:10:28 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4j6r34INNei7@anvil.ugrad.cs.ubc.ca>
  8. References: <4ig9su$jn9@garcia.efn.org>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10. Keywords: soundblaster
  11.  
  12. In article <4ig9su$jn9@garcia.efn.org>, Sonny Ovens <sovens@efn.org> wrote:
  13. >Does anybody out there have a sample of some code that woud record voice 
  14. >through the soundblaster, to a file? I am using C/C++. I am having 
  15. >problems doing it myself, since I really dont know where to start. I am 
  16.  
  17. You don't start in comp.lang.c. This newsgroup is for the discussion of the C
  18. language, not sound blaster cards.
  19.  
  20. >using the BLAST13 library, Although I would like to see something using 
  21. >any library available. All I need is the simplest program possible.
  22. >Also, does anybody have any Ideas on how to have the soundblaster tell me 
  23. >the frequency of a tone that is at the input of the sound card? I want my 
  24. >program to run diferent functions when certian tones are present at the 
  25. >input. Not DTMF tones, just a regular sine wave type tone. I will have it 
  26. >activate if the tone remains the same for .75 seconds, to avoid the SB 
  27. >interpreting voice tones as tones I want to decode.
  28.  
  29. A newsgroup about signal processing would be appropriate for this topic. It's
  30. not particular to the C language, or MSDOS.
  31.  
  32. I see that you did crosspost to comp.dsp already.
  33.  
  34. If you have one or a small number of definite frequencies that you wish to
  35. check for you can simply see how the signal correlates with an artificial
  36. reference waveform of the given frequency.
  37.  
  38. Basically, you project the input signal onto a basis consisting of a sine and a
  39. cosine function of the frequency you are trying to detect. Pretend that the
  40. signals and reference waveforms are giant vectors and you are taking a long
  41. running dot product---you multiply the signal with the sine, and with the
  42. cosine and accumulate the results into two separate running sums. Essentially,
  43. you are projecting the signal vector into the vector space spanned by the sine
  44. and cosine vector: you measure to what extent the signal has a component in the
  45. sine and in the cosine. These two are an orthogonal vector basis, because they
  46. are at 90 degrees to each other.
  47.  
  48. If the input signal frequency is close to the frequency of your sine and cosine
  49. function, it will ``harmonize'' with the two and you will get some numbers which
  50. roughly tells you the coefficients of the sine and cosine component present in
  51. your signal.  You can take these two numbers as a 2D vector whose direction
  52. gives you the phase angle, and length gives you the amplitude.
  53.  
  54. If you sample sections that are too short, the presence of noise may mask the
  55. signal too much. If you sample for too long, you will reject more and more
  56. frequencies that are close to what you are looking for, increasingly selecting
  57. for the precise frequency. Frequencies that are not quite equal to the one you
  58. are filtering for will cause a rotation of the phase vector (related to the
  59. beats you hear when you play two notes on a guitar that are close in
  60. frequency), which will cause cancellation over the long run. You have to
  61. experiment a little bit.
  62.  
  63. You also have to normalize the results by dividing by the length of the sine
  64. and cosine vector. You can do this by dividing by the sum of the squares of the
  65. cosine and sine samples alone.
  66.  
  67. Checking thus for the presence of some frequency or group of frequencies is
  68. easy, but determining an arbitrary pitch is not trivial.
  69.  
  70. -- 
  71.  
  72.